//
//  RWBluetoothService.h
//  RWBluetooth
//
//  Created by Ray on 2024/4/26.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

NS_ASSUME_NONNULL_BEGIN

@class RWBluetoothService;
@class RWBluetoothPeripheral;
@class RWBluetoothCharacteristic;

/**
   * 发现服务上的特征回调
   */
typedef void (^blueToothFindCharacteristicCallback)(NSArray<RWBluetoothCharacteristic *> *characteristics, NSError * _Nullable error);

@interface RWBluetoothService : NSObject

/// 服务名称
@property (nonatomic, strong, readonly) NSString *name;

/// 系统提供出来的服务
@property (nonatomic, strong) CBService *service;
@property (nonatomic, strong) NSArray *includedServices;

/// 服务所在的设备
@property (nonatomic, weak, readonly) RWBluetoothPeripheral *peripheral;

/// 服务的唯一标示
@property (nonatomic, strong, readonly) CBUUID *UUID;

/// 服务是否是开启状态
@property (nonatomic, assign) BOOL isOn;

/// 服务是否是可用状态
@property (nonatomic, assign) BOOL isEnabled;

/// 服务中所有的特征
@property(nonatomic, strong, readonly) NSMutableArray<RWBluetoothCharacteristic *> *characteristicArray;


/// 初始化方法
- (instancetype)initWithService:(CBService *)service;
- (instancetype)initWithService:(CBService *)service perpheral:(RWBluetoothPeripheral *)peripheral;


/// 查找服务中所有的特征
- (RWBluetoothCharacteristic *)searchCharacteristciWithCharacteristic:(CBCharacteristic *)characteristic;


/// 查找服务上的特征
- (void)discoverCharacteristicWithCallback:(blueToothFindCharacteristicCallback)callback;

- (void)discoverCharacteristicWithCharacteristicUUIDs:(NSArray<CBUUID *> * _Nullable)uuidArray
                                             callback:(blueToothFindCharacteristicCallback)callback;

/// 处理manager的连接结果
- (void)dealDiscoverCharacteristic:(NSArray *)characteristics error:(NSError *)error;

@end

NS_ASSUME_NONNULL_END
